package com.atguigu.tingshu.album.config.rabbit;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 专辑搜索RabbitMQ配置
 * @author Haoran Sun
 * @since 2024/08/20
 */


@Configuration
public class AlbumSearchRabbitConfig {

    /**
     * 交换机初始化
     */
    @Bean
    public Exchange albumSearchExchange(){
        return ExchangeBuilder.directExchange("album_search_exchange").durable(true).build();
    }

    /**
     * 队列初始化
     */
    @Bean
    public Queue albumSearchAddQueue(){
        return QueueBuilder.durable("add_album_search_queue").build();
    }

    /**
     * 队列初始化
     */
    @Bean
    public Queue albumSearchDeleteQueue(){
        return QueueBuilder.durable("delete_album_search_queue").build();
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding albumSearchAddBinding(
            @Qualifier("albumSearchExchange") Exchange albumSearchExchange,
            @Qualifier("albumSearchAddQueue") Queue albumSearchAddQueue
    ){
        return BindingBuilder
                .bind(albumSearchAddQueue)
                .to(albumSearchExchange)
                .with("album_search_add")
                .noargs();
    }

    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding albumSearchDeleteBinding(
            @Qualifier("albumSearchExchange") Exchange albumSearchExchange,
            @Qualifier("albumSearchDeleteQueue") Queue albumSearchDeleteQueue
    ){
        return BindingBuilder
                .bind(albumSearchDeleteQueue)
                .to(albumSearchExchange)
                .with("album_search_delete")
                .noargs();
    }


}
